package org.zjt.servletdemo.config;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;


@Aspect
public class WeavingAspect {

    private static final Logger LOGGER =Logger.getLogger(WeavingAspect.class);
    private static final Map<String,AtomicLong> ACCESS_COUNT=new ConcurrentHashMap<>();
    private static final String PACKAGE_SEPARATOR=".";


    @Pointcut("execution(* org.zjt.servletdemo.service.impl.*.*(..))")
    public void anyService(){}


    @Before("org.zjt.servletdemo.config.WeavingAspect.anyService()")
    public void log(JoinPoint joinPoint){
        System.out.println("Service Method " + joinPoint.getSignature().getName() + " Invocation!");
    }


    /*@Before("execution(* org.zjt.servletdemo.service.impl.*.*(..))")
    public void before(){
        LOGGER.info("--------dao-before------------");
    }

    @After("execution(* org.zjt.servletdemo.service.impl.*.*(..))")
    public void after(){
        LOGGER.info("--------dao-after------------");
    }

    @Around("execution(* org.zjt.servletdemo.service.impl.*.*(..))")
    public Object  around(ProceedingJoinPoint joinpoint)throws java.lang.Throwable{
        Long startTime=System.currentTimeMillis();
        Object[] args = joinpoint.getArgs();
        Object result=joinpoint.proceed(args);

        System.out.println(joinpoint.getSignature().getName());

        return result;
    }*/

    /*//抛出异常后处理
    @AfterThrowing(throwing="ex",pointcut="execution(* org.zjt.demo.api..*.*(..))")
    public void AfterExcepter(Throwable ex){
        LOGGER.error(String.format("---------抛出异常AfterExcepter:%s------------",ex));
        LOGGER.error(ExceptionApiHandler.getExceptionStack(ex));
    }*/


}
